#!/usr/bin/env ruby

ip="128.8.126.92"
file=ARGV[0]
#file="data/rtt_trace.full.dat"

f = File.open(file, "r")

# map unacked sequence numbers to timestamps
h = Hash.new { |h,k|
    h[k] = -1;
}

f.each_line do |line|
    timestamp,ip_id, s_ip, d_ip, s_port, d_port, seq, ack, win_sz, tot_sz, data_sz   = line.split
    if(s_ip == ip) # The sender is the server. Send a message
        h[seq] = timestamp
    end
    if(d_ip == ip) # Receiver is the server. Got an ack
        h.each_pair do |sn, ts| 
            if(ack > sn)
                print"%d\t%d\n" % [timestamp.to_i, timestamp.to_i - ts.to_i]
                h.delete(sn)
            end
        end
    end
end
